home *** CD-ROM | disk | FTP | other *** search
- @if-using not(ocl-file-listbuff)
- @use (ocl-file-listbuff)
- @if-using not(ocl-file-hide-buffer) @lib hide-buffer @fi
- @if-using not(ocl-file-buff-size) @lib buff-size @fi
- ;OCL{{{}}}
- ;OCL{{{ reference description
- @if-using ( FUN-REFERENCE ) ; 1 ;
- Provides a function, which opens a screen size window containing all
- active buffers. A menu appears for selecting one of the buffers.
- @fi
- ;OCL}}}
- ;OCL{{{ variables
- ( defvar ( l-b-old-no l-b-ind l-b-i l-b-dummy ) )
- ;OCL}}}
- ;OCL{{{ history
- ( history l-b-menu )
- ;OCL}}}
- ;OCL{{{ list-buffers
- ;OCL{{{ reference
- @if-using ( FUN-REFERENCE ) ; 2 ; list-buffers-called
- ;OCL{{{ @list-buff-ref list-buffers
- Open a screen-sized window and list all buffers. Each line contains:
-
- @ref-start-item buffernumber [D] [*] filename
- * marks a changed file
- D marks a directory or the list of edited files
- @ref-end-item
-
- A menu appears, for selecting the buffer, you want to edit now.
- newline-and-indent will return to the old buffer. There are items
- up/down in the menu, to scroll the buffer list.
-
- begin-prompt-macro and end-prompt-macro are used, to use the correct
- keytables/modes.
- ;OCL}}}
- @fi
- ;OCL}}}
- ( deffun list-buffers
- ( set l-b-old-no current-buffer-number
- set l-b-ind used-buffers
- open-hidden-dummy-buffer(false)
- set l-b-dummy current-buffer-number
- set l-b-i used-buffers
- ;OCL{{{ get all buffers
- do
- ( if <>(l-b-i current-buffer-number)
- ;OCL{{{ add entry to list
- ( goto-buffer-number l-b-i
- ;OCL{{{ get buffer-no,change and filename
- history-edit-filename l-b-menu ()
- beginning-of-line
- " ;
- " ;
- " ;
- counter l-b-ind
- " ;
- " ;
- " ;
- if test-file-changed ( "* ) else ( " ) fi
- if =(file-type 0) ( " ) else ( "D ) fi
- " ;
- " ;
- " ;
- newline-and-indent
- ;OCL}}}
- goto-buffer-number l-b-dummy
- ;OCL{{{ add to buffer
- goto-line-counter 1
- newline-and-indent
- previous-line
- get-history l-b-menu 0
- ;OCL}}}
- set l-b-ind -(l-b-ind 1)
- )
- ;OCL}}}
- fi
- set l-b-i -(l-b-i 1)
- )
- while l-b-i
- ;OCL}}}
- set-file-unchanged
- ;OCL{{{ gen menu string
- history-edit l-b-menu ()
- "down
- set l-b-i -(used-buffers 1)
- do
- ( beginning-of-line
- counter l-b-i
- " ;
- set l-b-i -(l-b-i 1)
- )
- while l-b-i
- beginning-of-line
- "up " ;
- newline-and-indent
- ;OCL}}}
- ;OCL{{{ show list
- beginning-of-fold
- end-of-line
- newline-and-indent
- end-of-fold
- beginning-of-line
- newline-and-indent
- full-size-buffer
- set-file-unchanged
- change-buffername "active-buffers newline-and-indent
- screen-on
- redraw-display
- ;OCL}}}
- ;OCL{{{ prompt for new buffer
- local
- ()
- ( set l-b-i l-b-old-no
- do
- (
- ;OCL{{{ prompt for target, active is old buffer
- set l-b-old-no l-b-i
- begin-prompt-macro
- menu-counter l-b-old-no ( history l-b-menu )
- end-prompt-macro
- ;OCL}}}
- case
- ;OCL{{{ show next page
- ( =(l-b-old-no 0) ( previous-page ) )
- ;OCL}}}
- ;OCL{{{ show previous page
- ( >=(l-b-old-no used-buffers) ( next-page ) )
- ;OCL}}}
- default
- ;OCL{{{ break from loop, new target found
- ( if >=(l-b-old-no current-buffer-number)
- ( set l-b-old-no +(l-b-old-no 1) )
- fi
- return-from-macro
- )
- ;OCL}}}
- esac
- )
- while true
- )
- ;OCL}}}
- ;OCL{{{ return to wished buffer
- screen-off
- goto-buffer-number l-b-old-no
- set l-b-old-no current-buffer-id
- goto-buffer-number l-b-dummy
- leave-hidden-dummy-buffer(l-b-old-no)
- set l-b-dummy 0
- ;OCL}}}
- )
- )
- ;OCL}}}
- ;OCL{{{ abort-hook-add
- @if-using not(ABORT-HOOK-ADD)
- @use (ABORT-HOOK-ADD)
- ( defmac abort-hook-add ( ) )
- @fi
- ( defmac abort-hook-add-saved ( abort-hook-add ) )
- ( undeclare ( abort-hook-add ) )
- ( defmac abort-hook-add
- ( abort-hook-add-saved
- if l-b-dummy
- ( set l-b-dummy 0
- goto-buffer-number l-b-dummy
- set-file-unchanged
- exit-buffer
- restore-buffer-layout
- goto-buffer-number l-b-old-no
- )
- fi
- )
- )
- ( undeclare ( abort-hook-add-saved ) )
- ;OCL}}}
- ;OCL{{{ reference hooks
- @if-using ( FUN-REFERENCE ) ; 3 ;
- The libary defines a macro `abort-hook-add' and a OCL tag
- ABORT-HOOK-ADD. Add this to your abort-macro. In this case, aborting
- the buffer listing will restore the old state!
- @fi
- ;OCL}}}
- ;OCL{{{ undelcares
- ( undeclare ( l-b-old-no l-b-ind l-b-i l-b-dummy ) )
- ;OCL}}}
- @fi
-